
package org.sopt.dev.ImgKnight.agent.RobotsExclusion;

import java.util.HashMap;

public class DefaultCacheEngine extends RobotsTxtCacheEngine<String, String[]> {

	private HashMap<String, String[]> hashMap = null;
	
	public DefaultCacheEngine(int limitSize) {
		super(limitSize);
		hashMap = new HashMap<String, String[]>(limitSize);
	}
	
	public String[] put(String key, String[] value) {
		if( hashMap.size() >= getLimitSize() ) {
			clear();
			assert(hashMap.size() < getLimitSize());
		}
		return hashMap.put(key, value);
	}
	
	public String[] get(String key) {
		super.totalAcces++;
		String[] rules = hashMap.get(key);
		if( rules != null ) {
			hitRate++;
			return rules;
		}
		else
			missrate++;
		return null;
	}
	
	public void clear() {
		hashMap.clear();
	}
	
	public int size() {
		return hashMap.size();
	}
	
}
